package net.suncaper.demo.service;

import net.suncaper.demo.domain.hotel_information;
import net.suncaper.demo.domain.hotel_informationExample;
import net.suncaper.demo.mapper.hotel_informationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class HotelManageServiceImpl implements HotelManageService {
    @Autowired
    private hotel_informationMapper hotel_informationMapper;

    @Override
    public List<hotel_information> findUser(String hotel_name) {
        hotel_informationExample example=new hotel_informationExample();

        if(hotel_name!=null&&!hotel_name.equals("")){
            example.createCriteria().andHotelNameLike("%"+hotel_name+"%");
        }
        return hotel_informationMapper.selectByExample(example);
    }


    @Override
    public void savehotel_information(hotel_information hotel_information) {
        if(hotel_information.getHotelId()== null|| hotel_information.getHotelId().equals("")) {
                hotel_informationMapper.insert(hotel_information);
        }else
        {
                hotel_informationMapper.updateByPrimaryKey(hotel_information);
        }
    }

    @Override
    public int deletehotel_information(int hotel_id) { return hotel_informationMapper.deleteByPrimaryKey(hotel_id); }
@Transactional
@Cacheable("hotel_information")
    public hotel_information findUserById(int hotel_id){ return hotel_informationMapper.selectByPrimaryKey(hotel_id); }

}
